package com.survey.service.impl;

import com.survey.dao.mapper.UserMapper;
import com.survey.pojo.data.AddressDO;
import com.survey.pojo.data.UserDO;
import com.survey.service.UserService;
import com.survey.pojo.vo.UserVO;
import com.survey.utils.Result;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <br/>
 * Created by jj on 2018/08/05
 */
@Service("userService")
public class UserServiceImpl implements UserService {

    @Resource
    private UserMapper userMapper;

    @Override
    public Result addUser(UserVO userVO) throws Exception {
        UserDO userDO = userMapper.selectUserByEmail(userVO.getEmail());
        if (userDO != null) {
            return new Result(-1, "用户已存在");
        }
        int count = userMapper.addUser(userVO);
        if (count > 0) {
            return Result.getSuccess("添加成功");
        }
        return Result.getFailure("添加失败");
    }

    @Override
    public void active(UserVO userVO) {
        int count = userMapper.active(userVO);
    }

    @Override
    public List<AddressDO> mapList() {
        List<AddressDO> addressDOS = userMapper.mapList();
        return addressDOS;
    }

    @Override
    public Result updateUser(UserVO userVO) throws Exception {
        return null;
    }

    @Override
    public Result findDetailUser(UserVO userVO) throws Exception {
        return null;
    }

    @Override
    public UserDO listUser(UserVO userVO) throws Exception {
        List<UserDO> userDOS = userMapper.listUser(userVO);
        if (userDOS != null && userDOS.size() != 0) {
            return userDOS.get(0);
        }
        return null;
    }

    @Override
    public Result listUserPage(UserVO userVO) throws Exception {
        return null;
    }

    @Override
    public Result countUser(UserVO userVO) throws Exception {
        return null;
    }

    @Override
    public Result deleteUser(UserVO userVO) throws Exception {
        return null;
    }

}